/**
 * 
 */
package dms.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import com.sun.org.apache.xml.internal.security.utils.Base64;

/**
 * @author 李健
 *
 */
public class PasswordUtil {
	/**
	 * 
	 * @param pwd
	 * @param algorithm 可用MD5 或者SHA-1
	 * @return
	 */
	public static String Digest(String pwd, String algorithm) {
		String encryptPassword = null;
		MessageDigest messageDigest = null;
		
		try {
			messageDigest = MessageDigest.getInstance(algorithm);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		
		messageDigest.update(pwd.getBytes());
		byte[] digest = messageDigest.digest();
		encryptPassword = Base64.encode(digest);
		return encryptPassword;
	}
	
	public static String MD5Digest(String pwd) {
		return Digest(pwd, "MD5");
	}

}
